package com.godofgamblers.hotelmanagementsystem.service.imp;

import com.godofgamblers.hotelmanagementsystem.dto.RoomsInfoDto;
import com.godofgamblers.hotelmanagementsystem.dto.TodaySummaryDto;
import com.godofgamblers.hotelmanagementsystem.mapper.CheckInInfoMapper;
import com.godofgamblers.hotelmanagementsystem.mapper.OrderMapper;
import com.godofgamblers.hotelmanagementsystem.mapper.UserMapper;
import com.godofgamblers.hotelmanagementsystem.mapper.WorkingMapper;
import com.godofgamblers.hotelmanagementsystem.pojo.CheckInfo;
import com.godofgamblers.hotelmanagementsystem.pojo.MoneyOfMonth;
import com.godofgamblers.hotelmanagementsystem.pojo.UserLevel;
import com.godofgamblers.hotelmanagementsystem.service.BusinessReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/*

@author huanglang

@create_time 2019-10-15 12:03

Nothing is difficult but bugs

*/
@Service
public class BusinessReportServiceImp implements BusinessReportService {

    @Autowired
    private WorkingMapper workingMapper;
    @Autowired
    private CheckInInfoMapper checkInInfoMapper;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private OrderMapper orderMapper;

    @Override
    public TodaySummaryDto getTodaySummaryDto(String today) {
        TodaySummaryDto dto = new TodaySummaryDto();
        //模糊查询
        today = today + "%";
        //查询出住房数量封装进dto
        dto.setTodayRoomsData(checkInInfoMapper.getRoomsDataByTime(today));
        //查询出今日总收入
        dto.setTodayIncome(orderMapper.getTodayMoney(today));
        //查询今日值班人员
        dto.setTodayWorker(workingMapper.getTodayWorker(today));
        //查询入住订单
        dto.setCheckInfos(checkInInfoMapper.getCheckInfoByDay(today));
        return dto;
    }

    @Override
    public RoomsInfoDto getRoomsInfoDto(String month) {
        RoomsInfoDto dto = new RoomsInfoDto();
        month = month + "%";
        List<Integer> rooms = checkInInfoMapper.getRoomsDataByTime(month);
        //查询出住房数量封装进dto
        dto.setMonthRoomsData(rooms);
        int total_rooms = 0;
        for (Integer room: rooms) {
            total_rooms += room;
        }
        dto.setTotalRooms(total_rooms);
        return dto;
    }

    @Override
    public List<CheckInfo> getCheckInfos(String searchType, String context) {
        List<CheckInfo> checkInfos = null;
        System.out.println(searchType);
        if (searchType.contains("身份证号")) {
            checkInfos = checkInInfoMapper.getCheckInfoByIdCard(context);
        } else if (searchType.contains("房间号")) {
            checkInfos = checkInInfoMapper.getCheckInfoByRoomNum(context);
        }else if (searchType.contains("姓名")) {
            checkInfos = checkInInfoMapper.getCheckInfoByName(context);
        }
        return checkInfos;
    }

    @Override
    public List<UserLevel> getUserCount() {
        List<UserLevel> userCount = null;
        userCount = userMapper.getUserCount();
        return userCount;
    }

    @Override
    public List<MoneyOfMonth> getYearMoneyCount(String year) {
        List<MoneyOfMonth> moneyOfMonth = null;
        year = year + "%";
        moneyOfMonth = orderMapper.getYearDataByYear(year);

        return moneyOfMonth;
    }
}
